package com.assistant.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class BaseConfig {
    @Bean
    CorsFilter getCorsFilter(){
        UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration=new CorsConfiguration();
        configuration.addAllowedMethod("*");//允许怎样的方法（post、get）通过
        configuration.addAllowedOrigin("*");//域名
        configuration.addAllowedHeader("*");//请求头
        source.registerCorsConfiguration("/**",configuration);
        return new CorsFilter(source);
    }
}